//
//  HYCViewController.m
//  HYC_TOOLS_OC
//
//  Created by hyc286716320 on 11/03/2022.
//  Copyright (c) 2022 hyc286716320. All rights reserved.
//

#import "HYCViewController.h"
#import <HYC_TOOLS_OC/HYC_TOOLS_OC.h>
#import <HYC_TOOLS_OC/HYC_TOOLS_OC_HEADER.h>

#import "HYCModel.h"

@interface HYCViewController ()


@property (nonatomic,strong)UILabel *key1;
@property (nonatomic,strong)UILabel *value1;
@property (nonatomic,strong)UILabel *key2;
@property (nonatomic,strong)UILabel *value2;

@property (nonatomic,strong)UILabel *time;

@property (nonatomic,assign)CGFloat differenceNumber;
@end

@implementation HYCViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.differenceNumber = 15;
    
    self.view.backgroundColor = UIColor.greenColor;
    
//    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
//    NSString *completePath = [documentPath stringByAppendingPathComponent:@"AUPrice.plist"];
//    
////    completePath = @"/Users/jy/Library/Containers/4E708A18-5630-4216-8908-F5E1C3A19E7B/Data/Library/Caches/data.plist";
//    
//    NSMutableArray *arr = [NSMutableArray arrayWithContentsOfFile:completePath];
//    
//    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:0];
//    
//    dict[@"price"] = @"666";
//    dict[@"time"] = @"2024-04-19 18:45:25";
//    
//    [arr addObject:dict];
//    
//    if( [arr writeToFile:completePath atomically:YES]) NSLog(@"写入plist成功");
//    else    NSLog(@"写入plist失败");
    
    
     
    [self JRDJAUPrice];
    
    [self timer];
    


}

- (void)timer{
    
    __block NSInteger time = 3000; //倒计时时间
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0, 0));
    dispatch_source_set_timer(_timer, DISPATCH_TIME_NOW, 1200 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
    dispatch_source_set_event_handler(_timer, ^{
        dispatch_async(dispatch_get_main_queue(), ^{
            
            if(time <= 0){
                //倒计时结束
                dispatch_source_cancel(_timer);
                
//                [self loading];
                
            }else{
                //倒计时进行时每次执行
                
                time = 3000;
                
                NSLog(@"执行了一次");
                
                
                [self loading];
                
                time--;
            }
        });
    });
    dispatch_resume(_timer);
}


- JRDJAUPrice {
    
    UIImageView *imageV = UIImageView.alloc.init;
    imageV.backgroundColor = UIColor.redColor;
    [self.view addSubview:imageV];
    imageV.image = @"666.png".H_image;
    
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.offset(0);
    }];
    
    
    [UILabel.alloc.init
        .H_text(@"金日打金(苏州街)店")
        .H_Font(@"150".H_font)
        .H_textColor(UIColor.blackColor)
        .H_addSubViewFoSuper(imageV) mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.offset(0);
            make.top.offset(100);
        }];
    
    self.key1 = UILabel.alloc.init
        .H_text(@"")
        .H_Font(@"150".H_font)
        .H_textColor(UIColor.blackColor)
        .H_addSubViewFoSuper(imageV);
    
    [self.key1  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(imageV.mas_centerY).offset(-100);
            make.left.offset(100);
    }];
    
    self.key2 = UILabel.alloc.init
        .H_text(@"")
        .H_Font(@"150".H_font)
        .H_textColor(UIColor.blackColor)
        .H_addSubViewFoSuper(imageV);
    [self.key2  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(imageV.mas_centerY).offset(100);
            make.left.offset(100);
    }];
    
    self.value1 = UILabel.alloc.init
        .H_text(@"")
        .H_Font(@"150".H_font)
        .H_textColor(UIColor.blackColor)
        .H_addSubViewFoSuper(imageV);
    [self.value1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.key1);
            make.right.offset(-100);
    }];
    
    self.value2 = UILabel.alloc.init
        .H_text(@"")
        .H_Font(@"150".H_font)
        .H_textColor(UIColor.blackColor)
        .H_addSubViewFoSuper(imageV);
    [self.value2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(imageV.mas_centerY).offset(100);
            make.right.equalTo(imageV.mas_right).offset(-100);
    }];
    
    self.key1.text = @"AU9999";
    self.value1.text = @"600元/克";
    
    self.key2.text = @"回收AU9999";
    self.value2.text = @"540元/克";
    
    
    self.time = UILabel.alloc.init
        .H_text(@"")
        .H_Font(@"100".H_font)
        .H_textColor(UIColor.blackColor)
        .H_addSubViewFoSuper(imageV);
    
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(imageV).offset(-100);
        make.bottom.equalTo(imageV).offset(-200);
    }];
    
    
    
    return self;
}


- (void)loading {
    
    
    
        
    

    
    
    [HYC_AFN getWithURLString:@"http://api.tanshuapi.com/api/gold/v1/shgold?key=feac9310ebc33d7c60a1dea3420ff1df" parameters:nil success:^(NSDictionary * responseObject) {
        
        
        
        
        
        
            
            NSDictionary *datas = responseObject[@"data"];
            NSArray *list = datas[@"list"];
            
            if (list.count) {
                
                for (NSDictionary *eveData in list) {
                    if ([eveData[@"type"] isEqualToString:@"AU99.99"]) {
                        
                        
                        
                        NSString *priceStr = eveData[@"price"];
                        NSString *timeStr = eveData[@"updatetime"];
                        self.value1.text = [NSString stringWithFormat:@"¥%.2f元/克",priceStr.floatValue + self.differenceNumber];
                        self.value2.text = [NSString stringWithFormat:@"¥%.2f元/克",priceStr.floatValue - self.differenceNumber];
                        self.time.text = timeStr;
                        
                        NSLog(@"金日日期:%@",timeStr);
                        NSLog(@"金日金价:%.2f",priceStr.floatValue + self.differenceNumber);
                    }
                }
                
            }
            
            
        
        
        NSLog(@"接口访问成功了");
            
        } failure:^(NSError *error) {
            
            NSLog(@"接口访问失败了");
            
        }];
}


- label {
    
    
    UILabel *label = [UILabel.alloc.init
        .H_text(@"这个label666")
        .H_frame(CGRectMake(0, 0, 100, 200))
        .H_backgroundColor(UIColor.greenColor)
        .H_textColor(@"333333".H_color)
        .H_textAlignment(NSTextAlignmentCenter)
        .H_Font([@"13" H_weight:UIFontWeightBold])
        .H_addSubViewFoSuper(self.view)
        .H_numberOfLines(0) addGuest:tapAction resutlBlock:^(UITapGestureRecognizer * _Nonnull gesture) {
          
            
            
            
        }];
        
    [label  mas_makeConstraints:^(MASConstraintMaker *make) {
        
        
        make.edges.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
                      
    NSLog(@"%@",HYCModel.H_RunTime_ProprtyList);
    NSLog(@"%@",HYCModel.H_RunTime_IvarList);
    NSLog(@"%@",HYCModel.H_RunTime_MethodList);
    
    return self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
